package com.ruoyi.patrol.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.patrol.vo.PtWorkRepairVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtWorkRepair;
import com.ruoyi.patrol.service.IPtWorkRepairService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报修工单信息Controller
 *
 * @author linan
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/work/repair")
public class PtWorkRepairController extends BaseController
{
    @Autowired
    private IPtWorkRepairService ptWorkRepairService;

    /**
     * 查询报修工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('work:repair:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtWorkRepair ptWorkRepair)
    {
        startPage();
        List<PtWorkRepairVO> list = ptWorkRepairService.selectPtWorkRepairList(ptWorkRepair);
        return getDataTable(list);
    }

    /**
     * 导出报修工单信息列表
     */
    @PreAuthorize("@ss.hasPermi('work:repair:export')")
    @Log(title = "报修工单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PtWorkRepair ptWorkRepair)
    {
        List<PtWorkRepairVO> list = ptWorkRepairService.selectPtWorkRepairList(ptWorkRepair);
        ExcelUtil<PtWorkRepairVO> util = new ExcelUtil<>(PtWorkRepairVO.class);
        util.exportExcel(response, list, "报修工单信息数据");
    }

    /**
     * 获取报修工单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:repair:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ptWorkRepairService.selectPtWorkRepairById(id));
    }

    /**
     * 新增报修工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:repair:add')")
    @Log(title = "报修工单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtWorkRepair ptWorkRepair)
    {
//        ptWorkRepair.setSource(getSource());
        return toAjax(ptWorkRepairService.insertPtWorkRepair(ptWorkRepair));
    }

    /**
     * 修改报修工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:repair:edit')")
    @Log(title = "报修工单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtWorkRepair ptWorkRepair)
    {
        return toAjax(ptWorkRepairService.updatePtWorkRepair(ptWorkRepair));
    }

    /**
     * 删除报修工单信息
     */
    @PreAuthorize("@ss.hasPermi('work:repair:remove')")
    @Log(title = "报修工单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptWorkRepairService.deletePtWorkRepairByIds(ids));
    }

    @Log(title = "修改报修工单状态", businessType = BusinessType.UPDATE)
    @PutMapping("updateStatus")
    public AjaxResult updateStatus(@RequestBody Map<String, Object> param)
    {
        return ptWorkRepairService.updateStatus(param);
    }
}
